import Request from '../js_sdk/luch-request/luch-request/index'
import {
	BASE_URL,
	ID,
	KEY
} from '@/config/index.js'
let http = new Request({
	baseURL:BASE_URL+'/1.1',
	header:{
		"X-LC-Id": ID,
		"X-LC-Key": KEY,
		"Content-Type": "application/json"
	}
})
let statusList = {
	'201':'操作成功',
	'200':'操作成功',
	'400':'操作失败'
}
http.interceptors.response.use((response) => { /* 对响应成功做点什么 可使用async await 做异步操作*/
  //  if (response.data.code !== 200) { // 服务端返回的状态码不等于200，则reject()
  //    return Promise.reject(response) // return Promise.reject 可使promise状态进入catch
 // if (response.config.custom.verification) { // 演示自定义参数的作用
  //   return response.data
  // }
  let {statusCode} = response
  uni.showToast({
  	title:statusList[statusCode],
	icon:'none'
  })
  console.log('响应拦截',response)
  return response
}, (response) => { /*  对响应错误做点什么 （statusCode !== 200）*/
  let {statusCode} = response
  uni.showToast({
  	title:statusList[statusCode],
  	icon:'none'
  })
  return Promise.reject(response)
})

export default http